package com.cszy.yydqbfq.adapter

import android.content.Context
import android.view.ViewGroup
import android.widget.ImageView
import com.bumptech.glide.Glide
import com.bumptech.glide.load.resource.bitmap.RoundedCorners
import com.bumptech.glide.request.RequestOptions
import com.chad.library.adapter4.BaseQuickAdapter
import com.chad.library.adapter4.viewholder.QuickViewHolder
import com.cszy.yydqbfq.R
import com.cszy.yydqbfq.bean.Song


class GeDanDetailListAdapter : BaseQuickAdapter<Song, QuickViewHolder>() {

    private var visiblePosition: Int = -1

    override fun onBindViewHolder(holder: QuickViewHolder, position: Int, item: Song?) {
        holder.setText(R.id.tv_music_name, item?.title)
        holder.setText(R.id.tv_author, item?.artist ?: "未知")
        Glide.with(context)
            .load(item?.cover)
            .placeholder(R.mipmap.ic_default)
            .error(R.mipmap.ic_default)
            .apply(
                RequestOptions()
                    .transform(RoundedCorners(8)) // 设置 4 个圆角，8dp
            )
            .into(holder.getView(R.id.iv_music_cover))
        holder.getView<ImageView>(R.id.iv_play_type).setOnClickListener {
            visiblePosition = if (visiblePosition == position) -1 else position
            notifyDataSetChanged()
        }
    }

    override fun onCreateViewHolder(
        context: Context,
        parent: ViewGroup,
        viewType: Int
    ): QuickViewHolder {
        return QuickViewHolder(R.layout.item_gedan_detail_list, parent)
    }
}